<html>
<head><meta charset="utf-8"><title>Early return from a MIR `Visitor`? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html">Early return from a MIR `Visitor`?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178320748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178320748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178320748">(Oct 16 2019 at 19:27)</a>:</h4>
<p>There's <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/qualify_min_const_fn.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/qualify_min_const_fn.rs">multiple</a> <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/qualify_consts.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/transform/qualify_consts.rs">places</a> in const qualification and validation where Visitor is basically reimplemented only so it can eagerly return a result.</p>
<p>I wonder if we could add an associated return type to <code>Visitor</code> that must be either something implementing <code>Try</code> or an empty tuple so that code like this can take advantage of the existing structural recursion in <code>Visitor</code>? Existing visitors would not have to change except maybe to specify <code>type BreakVal = ()</code> (I'm not sure if associated type defaults are usable).</p>



<a name="178375327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178375327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178375327">(Oct 17 2019 at 12:22)</a>:</h4>
<p>associated type defaults are not usable, because every implementor that changes it will have to reimplement all methods (even those with default bodies)</p>



<a name="178384997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178384997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178384997">(Oct 17 2019 at 14:15)</a>:</h4>
<p>It could just be a plain generic</p>



<a name="178385055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178385055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178385055">(Oct 17 2019 at 14:16)</a>:</h4>
<p>I'd like to review the MIR visitor somewhat, in light of the changes that <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> was making; I'm wondering if there's a less general structure that might work better</p>



<a name="178510568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178510568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178510568">(Oct 18 2019 at 21:03)</a>:</h4>
<p>I did a proof-of-concept in <a href="https://github.com/rust-lang/rust/issues/65572" target="_blank" title="https://github.com/rust-lang/rust/issues/65572">#65572</a></p>



<a name="178512540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178512540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178512540">(Oct 18 2019 at 21:37)</a>:</h4>
<p>One of the reasons I'm interested in this is that it would be useful in <a href="https://github.com/rust-lang/rust/issues/63812" target="_blank" title="https://github.com/rust-lang/rust/issues/63812">#63812</a> (<span class="user-mention" data-user-id="119009">@eddyb</span> )</p>



<a name="178513048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Early%20return%20from%20a%20MIR%20%60Visitor%60%3F/near/178513048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Early.20return.20from.20a.20MIR.20.60Visitor.60.3F.html#178513048">(Oct 18 2019 at 21:45)</a>:</h4>
<p>Also, I haven't looked at the perf implications of this. If the queue is ever empty I'll trigger a perf run (seems unlikely). I think I'd need to add <code>#[inline]</code> to the <code>Try</code> impl for <code>()</code> first.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>